package router

import (
	"douhu_backend/internal/controller/auth"
	"douhu_backend/internal/infra/logger"
	"douhu_backend/internal/services"
	authService "douhu_backend/internal/services/auth"

	"github.com/kataras/iris/v12"
)

// InitAuthRoutes 初始化认证相关的受保护路由（需要鉴权）
func InitAuthRoutes(app *iris.Application, sm *services.Manager) error {
	// 从服务管理器获取服务
	authSvc := sm.GetAuth()

	// 初始化控制器
	authController := auth.NewAuthController(authSvc)

	// 初始化认证中间件
	authMiddleware := authService.NewAuthMiddleware(sm.GetJWT(), sm.GetDAOManager().Auth)

	// 创建受保护的认证路由组（需要鉴权）
	protectedGroup := app.Party("/api/auth", authMiddleware.RequireAuth)
	protectedGroup.Get("/user", authController.GetUserInfo)      // 获取用户信息
	protectedGroup.Put("/profile", authController.UpdateProfile) // 更新用户资料
	// TODO: 实现文件上传路由
	// protectedGroup.Post("/upload/avatar", uploadService.UploadAvatar)

	logger.Info("protected auth routes initialized successfully")
	return nil
}
